﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public class VWebConfigManagerPage : System.Web.UI.Page
	{
		public void ShowAlert(string key, string content)
		{
			if (Page.ClientScript.IsStartupScriptRegistered(key))
			{
				Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), key, "alert('" + content + "');", true);
			}
		}

		public string GetAmassExceptionMessage(System.Exception ex)
		{
			string message = ex.Message + "\r\n";

			if (ex.InnerException != null)
				message += GetAmassExceptionMessage(ex.InnerException);

			return message;
		}

		protected void ShowExceptionAlert(Exception ex)
		{
			ShowAlert("Result", GetAmassExceptionMessage(ex).Replace("\r\n", @"\n").Replace("'", ""));
		}
		protected void ShowAlert_DetailsView_ItemInserted(DetailsViewInsertedEventArgs e)
		{
			if (e.Exception != null)
			{
				e.ExceptionHandled = true;
				ShowExceptionAlert(e.Exception);
				return;
			}

			ShowAlert("Result", "Success");
		}
		protected void ShowAlert_DetailsView_ItemUpdated(DetailsViewUpdatedEventArgs e)
		{
			if (e.Exception != null)
			{
				e.ExceptionHandled = true;
				ShowExceptionAlert(e.Exception);
				return;
			}

			ShowAlert("Result", "Success");
		}
		protected void ShowAlert_DetailsView_ItemDeleted(DetailsViewDeletedEventArgs e)
		{
			if (e.Exception != null)
			{
				e.ExceptionHandled = true;
				ShowExceptionAlert(e.Exception);
				return;
			}

			ShowAlert("Result", "Success");
		}
	}
}